//
//  LBMeOrderDetailController.m
//  loveBeen
//
//  Created by lc on 2016/11/22.
//  Copyright © 2016年 loveBeen. All rights reserved.
//

#import "LBMeOrderDetailController.h"
#import "LBMeDetailOrderCell.h"
#import "LBMeDetailOrderModer.h"

static NSString *ID = @"cell_id";

@interface LBMeOrderDetailController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,weak)UITableView *tableView;
@property(nonatomic,weak)NSArray<LBMeDetailOrderModer *> *arryList;
@end

@implementation LBMeOrderDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
    [self setupUI];
    
    //设置模型属性标志
    self.arryList.lastObject.isLast = YES;
    self.arryList.firstObject.isFirst = YES;

    [self setSegment];
    
    self.tableView.userInteractionEnabled = NO;
}

//设置segmented
-(void)setSegment {
    
    NSArray *array = [NSArray arrayWithObjects:@"订单状态",@"订单详情", nil];
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:array];
    
    //设置颜色
    segment.tintColor = [UIColor colorWithRed:253/255.0 green:212/255.0 blue:50/255.0 alpha:1];
    //设置选中状态
    segment.selectedSegmentIndex = 0;
    
    //设置字体样式
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSForegroundColorAttributeName,[UIFont fontWithName:@"AppleGothic"size:14],NSFontAttributeName ,nil];
    [segment setTitleTextAttributes:dic forState:UIControlStateNormal];
    //添加到导航栏titl上
    self.navigationItem.titleView = segment;
    
}

//加载数据
-(void)loadData {
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"LBMeDetailOrder.plist" withExtension:nil];
    NSArray *array = [NSArray arrayWithContentsOfURL:url];
    self.arryList = [NSArray yy_modelArrayWithClass:[LBMeDetailOrderModer class] json:array];
    
    [self.tableView reloadData];
}

- (void)setupUI{
   //创建tableView视图
    UITableView *tableView = [[UITableView alloc] init];
    
    [self.view addSubview:tableView];
    tableView.rowHeight = 80;
    
    //关联
    self.tableView = tableView;
    
    //设置代理
    tableView.dataSource = self;
    tableView.delegate = self;
    
    //约束
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.view);
    }];
    
    //创建一个footerView隐藏下面cell间距线
    UIView *footerView = [[UIView alloc] init];
    tableView.tableFooterView = footerView;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"LBMeDetailOrder" bundle:nil] forCellReuseIdentifier:ID];
}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.arryList.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LBMeDetailOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    cell.model = self.arryList[indexPath.row];
    return cell;
}

@end
